import { Alova } from '@/utils/http/alova/index';

// 器具箱账户数据结构
interface CabinetAccountInfo {
  id: string;
  cabinetId: string;
  cabinetCode: string;
  orgId: string;
  workingState: number; // 0: 锁定, 1: 解锁
  photoPath?: string;
  createTime?: string;
  updateTime?: string;
}

const baseApi = '/web/proj/cabinet/account';

/**
 * 根据ID获取器具箱账户信息
 */
export function getCabinetAccountById(params: { id: string }) {
  return Alova.Post<InResult<CabinetAccountInfo>>(baseApi + '/byId', { params });
}

/**
 * 根据器具箱ID获取账户信息
 */
export function getCabinetAccountByCabinetId(params: { cabinetId: string }) {
  return Alova.Post<InResult<CabinetAccountInfo>>(baseApi + '/byCabinetId', { params });
}

/**
 * 根据组织ID获取器具箱账户列表
 */
export function getCabinetAccountByOrgId(params: { orgId: string }) {
  return Alova.Post<InResult<CabinetAccountInfo[]>>(baseApi + '/byOrgId', { params });
}

/**
 * 添加器具箱账户
 */
export function addCabinetAccount(params: Partial<CabinetAccountInfo>) {
  return Alova.Post<InResult<CabinetAccountInfo>>(baseApi + '/add', { params });
}

/**
 * 更新器具箱账户
 */
export function updateCabinetAccount(params: CabinetAccountInfo) {
  return Alova.Post<InResult<CabinetAccountInfo>>(baseApi + '/update', { params });
}

/**
 * 删除器具箱账户
 */
export function removeCabinetAccount(params: { id: string }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/remove', { params });
}

/**
 * 锁定/解锁器具箱
 * @param params { id: string, workingState: 0 | 1 } 0: 锁定, 1: 解锁
 */
export function lockOrUnlockCabinet(params: { id: string; workingState: 0 | 1 }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/lockOrUnlock', { params });
}